<template>
	<view class="content">
		<view class="psd">
			<view class="password">
				<view class="password_title">
					原密码
				</view>
				<input type="password" value="" v-model="oldpassword"/>
			</view>
			<view class="password">
				<view class="password_title">
					设置密码
				</view>
				<input type="password" value=""  v-model="password"/>
			</view>
			<view class="password">
				<view class="password_title">
					重复密码
				</view>
				<input type="password" value="" v-model="password1" />
			</view>
		</view>
		<view class="save" @click="psd()">保存</view>
	</view>
</template>

<script>
import getdata from '@/common/ajax.js';	
	export default {	
		data() {
			return {
				oldpassword:'',
				password:'',
				password1:'',
			}
		},
		onLoad() {

		},
		methods: {
			psd(){
				var _this = this
				var token = uni.getStorageSync('token')
				if(_this.oldpassword == ''){
					getdata.shou('请输入原密码')
				}else if(getdata.kongbai(_this.oldpassword) == false){
					getdata.shou('原密码格式不正确')
				}else if(_this.password == ''){
					getdata.shou('请输入新密码')
				}else if(getdata.kongbai(_this.password) == false){
					getdata.shou('新密码格式不正确')
				}else if(_this.password1 == ''){
					getdata.shou('请再次输入密码')
				}else if(_this.password1 != _this.password){
					getdata.shou('两次输入密码不一致')
				}else{
					var data = {
						oldpassword:_this.oldpassword,
						password:_this.password,
					}
					uni.showLoading({
					    title: '保存中'
					});
					uni.request({
						url: getdata.websiteUrl + '/user/update_password',
						data: data,
						dataType: 'json',
						method: 'POST',
						header:{'content-type': "application/x-www-form-urlencoded",token:token},
						success: res => {
							console.log(res)
							uni.hideLoading();
							if (res.data.code == 1) {
								// getdata.shou(res.data.msg);
								// setTimeout(function(){
								// 	uni.navigateBack(); 
								// },1500)
								getdata.shou('修改密码成功，请重新登录')
								setTimeout(function(){
									uni.clearStorage();
									uni.reLaunch({
										url: '../login/login'
									}); 
								},1500)
							}else if(res.data.code == 401){
								getdata.shou('请登录')
								uni.reLaunch({
									url: '../login/login'
								});
							}else{
								getdata.shou(res.data.msg)
							} 
						},
						fail: err => {
							uni.hideLoading();
							getdata.shou('服务器断开链接')
						}
					});
				}
			}
		}
	}
</script>

<style lang="scss">
@import '../../../static/iconfont/iconfont.css';	
.content{
	box-sizing: border-box;
	padding: 0 75rpx;
	.psd{
		margin-top: 200rpx;
	}
	.password{
		width: 100%;
		border-bottom: 2rpx solid #E0E0E0;
		margin-bottom: 40rpx;
		.password_title{
			font-size: 26rpx;
			font-family: PingFang SC;
			color: #8D8D97;
		}
		input{
			width: 100%;
			height: 70rpx;
		}
	}
	.save{
		width: 360rpx;
		height: 80rpx;
		line-height: 80rpx;
		background: #1578F2;
		box-shadow: 0rpx 3rpx 15rpx 1rpx rgba(21, 120, 242, 0.81);
		border-radius: 40rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
		margin: 200rpx auto;
		// position: fixed;
		// bottom:150rpx;
		// left:195rpx;
	}
}
</style>
